import { createRouter,createWebHistory,RouteRecordRaw } from 'vue-router'
import { App} from 'vue'

const routes:RouteRecordRaw[] = [
    {
        path:'/',
        redirect:'/login'
    },
    {
        path:'/login',
        name:'Login',
        // component:()=>{ import() }  这个没有返回值  是错的。
        // component:()=> import()    这个才是对的
        component:()=>import('@/views/login/Login.vue')
    },
    {
        path:'/home',
        name:'Home',
        component:()=>import('../views/Home.vue'),
       
    },
    {
        path:'/goods',
        name:'Goods',
        component:()=>import('../views/Goods.vue'),
       
    },
    {
        path:'/user',
        name:'User',
        component:()=>import('../views/User.vue'),
       
    } ,
    {
        path:'/order',
        name:'Order',
        component:()=>import('../views/Order.vue'),
       
    }  ,
    {
        path:'/myfree',
        name:'Myfree',
        component:()=>import('../views/MyFree.vue'),
       
    } ,
    { path: '/:pathMatch(.*)*', name: 'not-found', component: ()=>import('@/views/Error.vue') }            
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

// export default router;  优化一下写法
// 直接导出一个方法
router.resolve({
    name: 'not-found',
    params: { pathMatch: ['not', 'found'] },
  }).href 
export const initRouter =(app:App<Element>)=>{
        app.use(router)
}